package com.google.code.jholidays.events.properties;

import com.google.code.jholidays.core.EventDescriptor;
import com.google.code.jholidays.events.DependentEvent;
import com.google.code.jholidays.events.DependentEventFactory;
import com.google.code.jholidays.events.IEvent;
import com.google.code.jholidays.events.parameters.Offset;

/**
 * Encapsulates properties needed for construction of {@link DependentEvent}
 * instances.
 * 
 * @author tillias
 * @see DependentEventFactory
 * @see DependentEvent
 * 
 */
public class DependentEventProperties extends AbstractEventProperties {

    /**
     * Creates new instance of properties
     * 
     * @param descriptor
     *            Event descriptor
     * @param parent
     *            Parent event. Can't be null
     * @param offset
     *            Offset of dependent event from it's parent. Can't be null
     * @throws IllegalArgumentException
     *             Thrown if any parameter passed to constructor is null or if
     *             parent's id field isn't equal to descriptor's parentID field
     */
    public DependentEventProperties(EventDescriptor descriptor, IEvent parent,
	    Offset offset) throws IllegalArgumentException {
	super(descriptor, parent);

	if (parent == null)
	    throw new IllegalArgumentException("Parent event is null");

	if (offset == null)
	    throw new IllegalArgumentException("Offset is null");

	if (parent.getID() != descriptor.getParentID())
	    throw new IllegalArgumentException(
		    "Descriptor's parentID doesn't match to parent event's one");

	this.offset = offset;
    }

    /**
     * Gets the offset of dependent event from parent one
     * 
     * @return Offset of dependent event
     */
    public Offset getOffset() {
	return offset;
    }

    Offset offset;
}
